$('#submit-register').click(function() {
	var firstname = $('#inputFirstName').val(),
		lastname = $('#inputLastName').val(),
		nickname = $('#inputNickname').val(),
		password = $('#inputPassword').val();
	
	if(firstname === '' || lastname === '' || nickname === '' || password === '') {
		alert('Please fill in all fields!');
	} else {
		registerUser(firstname, lastname, nickname, password);
	}
});

var registerUser = function(firstname, lastname, nickname, password) {
	$.ajax({
		type : 'POST',
		url : 'api/user',
		contentType : "application/json",
		data : JSON.stringify({ lastname: lastname, firstname: firstname, nickname: nickname, password: password})
	}).fail(function(jgXHR, textStatus) {
		alert(jgXHR.status + ': ' + textStatus);
	}).success(function(data, textStatus, request) {
		localStorage.setItem('access-token', request.getResponseHeader('access-token'));
		localStorage.setItem('username', nickname);
		window.location.href = "index.html";
	});
};